<?php
	require_once '../lib/upload.class.php';
	require_once '../../lib/sql.utils.php';
	
	$bookName = $_POST ['name'];
	$pageNumb = $_POST ['page-numb'];
	$categoryDetailId = $_POST['select-category-detail'];
	$authorId = $_POST ['select-author'];
	$bookStoreId = $_POST ['select-book-store'];
	$publisherId = $_POST ['select-publisher'];
	$bookSize = $_POST['size'];
	$bookPrice = $_POST['price'];
	$bookDiscount = $_POST['discount'];
	$description = $_POST ['description'];
	$image;
	if (! empty ( $_POST )) {
		$upload = new Upload ( 'upload' );
		$upload->setFileExtension ( 'gif|jpg|png' );
		$upload->setFileSize ( 5000 );
		$upload->setUploadDir ( '../../images/book/' );
		if ($upload->isVail () == false) {
			$upload->upload ( true );
		}
		$image = $upload->getFileName();
		if($image == NULL){
			$image = $_POST['isImage'];
		}
	}
	
	$sql_util = new SqlUtils();
	$colList = array('bookName','categoryDetailId','bookPageNumb','bookImage','authorId','bookStoreId','publisherId','bookSize','bookPrice','bookDiscount','bookDescription');
	$rowList = array('"'.$bookName.'"','"'.$categoryDetailId.'"','"'.$pageNumb.'"','"'.$image.'"','"'.$authorId.'"','"'.$bookStoreId.'"','"'.$publisherId.'"','"'.$bookSize.'"','"'.$bookPrice.'"','"'.$bookDiscount.'"','"'.$description.'"');
	$tbl = 'books';
	$tblId = 'bookId';
	$id = $_POST['id'];
	$result = $sql_util->updateRows($colList,$rowList,$tbl,$tblId,$id);
	//var_dump($sql_util->updateRows($colList,$rowList,$tbl,$tblId,$id));
	if($result == true) echo 'success';
	else {
		echo 'error';
	}
	header("location:../index.php");
?>